Skip to content

Reject non-string inputs in IP address validators - #579

Open
Aschenbath wants to merge 1 commit into
python-validators:masterfrom
Aschenbath:fix/non-string-ip-inputs-578
Open

Aschenbath wants to merge 1 commit into
python-validators:masterfrom
Aschenbath:fix/non-string-ip-inputs-578

Conversation

@Aschenbath

Copy link
Copy Markdown

ipv4() and ipv6() currently accept integers, booleans, packed bytes and network tuples through ipaddress; strict CIDR and private-address options can instead raise AttributeError on those values. Reject non-string inputs before calling string methods or ipaddress, returning the normal ValidationError result.

Fixes #578.

The public str annotations remain unchanged. The two runtime guards have narrowly scoped Pyright annotations because they protect callers that do not use static type checking.

Validation on Windows / Python 3.12: the new non-string cases have 31 failures and 13 passes before the fix; afterward the full suite passes (1,560 tests). Tox lint, type, format and SAST checks pass, as does git diff --check. Other Python versions were not run locally.

Developed and validated with assistance from OpenAI Codex.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ipv4() and ipv6() accept non-string values, and ipv4() raises AttributeError with private=

1 participant